package com.leyou.order.controller;

import com.leyou.order.dto.OrderDTO;
import com.leyou.order.service.OrderService;
import com.leyou.order.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;


    /**
     * 保存订单
     * @param orderDTO
     * @return
     */
    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody OrderDTO orderDTO){
        return ResponseEntity.ok(orderService.createOrder(orderDTO));
    }
    /**
     * 根据id查询订单信息
     */
    @GetMapping("{id}")
    public ResponseEntity<OrderVO> queryOrderById(@PathVariable("id") Long id){
        return ResponseEntity.ok(orderService.queryOrderById(id));
    }

    /**
     * 获取二维码支付超链接
     */
    @GetMapping("url/{id}")
    public ResponseEntity<String> getPayUrl(@PathVariable("id") Long id){
        return ResponseEntity.ok(orderService.getPayUrl(id));
    }
    /**
     * 查询支付状态
     */
    @GetMapping("state/{id}")
    public ResponseEntity<Integer> queryPayStatus(@PathVariable("id") Long id){
        return ResponseEntity.ok(orderService.queryPayStatus(id));
    }
}
